package com.heima.search.controller.v1;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.heima.search.service.AuthorService;
import com.heima.model.article.pojos.ApAuthor;
import com.heima.model.common.dtos.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/author")
public class ApAuthorController {
    @Autowired
    AuthorService authorService;

    /**
     *      根据APUser id  查询作者信息
     * @param userid
     * @return
     */
    @GetMapping("/findByUserId/{userId}")
    public ResponseResult<ApAuthor> findUserById(@PathVariable("userId") Integer userid){
        ApAuthor apAuthor = authorService.getOne(
                Wrappers.<ApAuthor>lambdaQuery().eq(ApAuthor::getUserId, userid)
        );
        return ResponseResult.okResult(apAuthor);
    }

    @PostMapping("/save")
    public ResponseResult save(@RequestBody ApAuthor apAuthor){
        authorService.save(apAuthor);
        return ResponseResult.okResult();
    }


}
